Skip to content

feat: followup compaction — automatic context summarization for long conversations#54

Draft
Simon-Free wants to merge 4 commits intoSafeRL-Lab:mainfrom
Simon-Free:pr9-followup-compaction
Draft

feat: followup compaction — automatic context summarization for long conversations#54
Simon-Free wants to merge 4 commits intoSafeRL-Lab:mainfrom
Simon-Free:pr9-followup-compaction

Conversation

@Simon-Free
Copy link
Copy Markdown

@Simon-Free Simon-Free commented Apr 17, 2026

Changes (complete rewrite)

  • followup_compaction.py: Destruction-based compaction (not stubbing), compact_assistant_xml + selective variant, thinking block stripping, cache breakpoint marking, build_messages_for_api integration
  • tests/test_followup_compaction.py: 28 tests covering XML compaction, selective compaction, tool history destruction, interrupted turn preservation, thinking strip, cache breakpoint

Breaking change: replaces stub-based compaction with full content destruction at user boundaries.

Port of bouzecode followup_compaction rewrite.

@Simon-Free Simon-Free marked this pull request as draft April 17, 2026 19:46
Simon FREYBURGER and others added 3 commits April 18, 2026 09:30
Remove compact_assistant_xml, compact_assistant_xml_selective, _xml_replacer,
_build_tc_lookup and _TOOL_USE_RE. These functions compact inline
<tool_use name=... id=...>...</tool_use> XML blocks inside assistant message
content, which only exist on providers that don't natively support
tool_use blocks (e.g. AWS Bedrock socle in bouzecode). Upstream cheetahclaws
uses the native Anthropic content: [{"type":"tool_use", ...}] format, so
these functions early-returned on every call and the compact_tool_history
branch that invoked compact_assistant_xml was a no-op.

Also fix _apply_context_gc which was wrapped in a double try/except where
the outer pass was unreachable, and which imported only apply_gc while
referencing inject_notes and prepend_verbatim_audit (NameError when
gc_state had entries). Replaced with a single try that imports all three
names and cleanly returns on ImportError if PR SafeRL-Lab#55 isn't deployed
alongside.

Test file drops the TestCompactAssistantXml / TestCompactAssistantXmlSelective
classes that exercised the removed functions.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant